import { NIcon, NTag, NSpace, NButton } from 'naive-ui'

interface TableButtonType<T> {
  label: string
  onClick: (row: T) => void
}

export const renderIcon = (icon: Component) => {
  return () => h(NIcon, null, { default: () => h(icon) })
}

export const renderTag = (name: string, type: NTagType = 'info') => {
  return h(NTag, { type: type }, { default: () => name })
}

export const createTableButtons = <T = unknown>(buttons: TableButtonType<T>[], row: T) => {
  return h(NSpace, () =>
    buttons.map((ele) =>
      h(
        NButton,
        {
          secondary: true,
          type: 'info',
          size: 'small',
          onClick: () => ele.onClick(row)
        },
        { default: () => ele.label }
      )
    )
  )
}
